Micron Document




Java syntax
part 29/46 · 86.7 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
static - Makes the method static and accessible without creation of a class instance. However static methods cannot access non-static members in the same class.
final - Declares that the method cannot be overridden in a subclass.
native - Indicates that this method is implemented through JNI in platform-dependent code. Actual implementation happens outside Java code, and such methods have no body.
strictfp - Declares strict conformance to IEEE 754 in carrying out floating-point operations.
synchronized - Declares that a thread executing this method must acquire monitor. For synchronized methods the monitor is the class instance or java.lang.Class if the method is static.
• Access modifiers - Identical to those used with classes.

Final methods

A final method cannot be overridden or hidden by subclasses.cite-ref-5[5] This is used to prevent unexpected behavior from a subclass altering a method that may be crucial to the function or consistency of the class.cite-ref-6[6]

Example:

public class Base
{
public void m1() {...}
public final void m2() {...}
public static void m3() {...}
public static final void m4() {...}
}
public class Derived extends Base
{
public void m1() {...} // OK, overriding Base#m1()
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────